package com.ray.ioc.core;

import android.content.Context;
import android.view.LayoutInflater;

/**
 * 控制反转的LayoutInflater，用于获取原生控件的自定义属性
 * Created by Ray on 2015/9/11.
 */
public class IOCLayoutInflater extends LayoutInflater {

    public IOCLayoutInflater(LayoutInflater original, Context newContext,
                             Object ioc) {
        super(original, newContext);
        setUpLayoutFactory(ioc);
    }

    private void setUpLayoutFactory(Object ioc) {
        if (!(getFactory() instanceof IOCFactory)) {
            setFactory(new IOCFactory(this, getFactory(),ioc));
        }
    }
    @Override
    public LayoutInflater cloneInContext(Context newContext) {
        return new IOCLayoutInflater(this,newContext,((IOCFactory)getFactory()).getBaseIOC());
    }
}
